#include "handleinterface.h"
#include "src/Entity/clientdefect.h"
#include "src/Utils/inifilehelper.h"
#include "src/Strategypatttern/strategycontenxtbase.h"

//-------------------一级处理-----------------------
void DefectOneHandle::handle(NormalDetectBase &n,
                             VerticalLengthDetectBase &v,
                             FrequencyDetectBase &f,
                             DirectLevelBase &d,
                             BesideDetectBase &b,
                             SteelInfo *steelinfo)
{
    //等级策略 3个等级
    strategyContext strategy;
    strategy.SetStargy(new strategyDetectOneLevel);

    //条件策略 5条策略
    conditionContext conditionStrategy;

    //这里应该要执行一级的判断方式
    strategy.execute(conditionStrategy,n,v,f,d,b,steelinfo);
    if(this->nextHandle){
        nextHandle->handle(n,v,f,d,b,steelinfo);
    }
    emit DetectFinish(steelinfo);

}

//-------------------二级处理-----------------------
void DefectTwoHandle::handle(NormalDetectBase &n,
                             VerticalLengthDetectBase &v,
                             FrequencyDetectBase &f,
                             DirectLevelBase &d,
                             BesideDetectBase &b,
                             SteelInfo *steelinfo)
{
    strategyContext strategy;
    strategy.SetStargy(new strategyDetectTwoLevel);

    conditionContext conditionStrategy;

    strategy.execute(conditionStrategy,n,v,f,d,b,steelinfo);
    if(steelinfo->getLevel() !=2 && this->nextHandle){
        nextHandle->handle(n,v,f,d,b,steelinfo);
    }
    else
    {
        emit DetectFinish(steelinfo);
    }
}

//-------------------三级处理-----------------------
void DefectThreeHandle::handle(NormalDetectBase &n,
                               VerticalLengthDetectBase &v,
                               FrequencyDetectBase &f,
                               DirectLevelBase &d,
                               BesideDetectBase &b,
                               SteelInfo *steelinfo)
{
    qDebug()<<"正在执行等级判定。。。。";
    strategyContext strategy;
    conditionContext conditionStrategy;
    strategy.SetStargy(new startegyDetectThreeLevel);
    strategy.execute(conditionStrategy,n,v,f,d,b,steelinfo);
    if(steelinfo->getLevel() !=3 && this->nextHandle){
        nextHandle->handle(n,v,f,d,b,steelinfo) ;
    }
    else
    {
        emit DetectFinish(steelinfo);
    }

    // emit DetectFinish(steelinfo);

}
